package com.yitongmao.activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;

import com.yitongmao.yitmfruit.R;
import com.zhy.autolayout.AutoLinearLayout;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class InvoiceActivity extends AppCompatActivity {
    @Bind(R.id.mFaPiaotaitou)
    AutoLinearLayout mFaPiaotaitou;
    @Bind(R.id.mInput)
    AutoLinearLayout mInput;
    @Bind(R.id.idn_back)
    Button idnBack;
    private boolean flagbukai = true;
    private boolean flagmingxi = true;
    private boolean flaggeren = true;
    private boolean flagdanwei = true;
    @Bind(R.id.mGeRen)
    CheckBox mGeRen;
    @Bind(R.id.mMDanWei)
    CheckBox mMDanWei;
    @Bind(R.id.mMingXi)
    CheckBox mMingXi;
    @Bind(R.id.mBuKai)
    CheckBox mBuKai;
    private TextView tv_tie;
    private String invoiceName="个人";
    private EditText mNaShuiRenShiBieHao;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        immerSion();
        setContentView(R.layout.activity_invoice);
        ButterKnife.bind(this);
        initView();
        idnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                InvoiceActivity.this.finish();
            }
        });
    }
    private void initView() {
        mNaShuiRenShiBieHao = (EditText) findViewById(R.id.mNaShuiRenShiBieHao);
        tv_tie = (TextView) findViewById(R.id.tv_tie);
        tv_tie.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String identifyNumber = mNaShuiRenShiBieHao.getText().toString().trim();
                Intent intent=new Intent(InvoiceActivity.this,PlaceOrderActivity.class);
                intent.putExtra("invoiceType","纸质发票");
                intent.putExtra("invoiceName",invoiceName);
                intent.putExtra("identifyNumber",identifyNumber);
                startActivity(intent);
            }
        });
    }

    @OnClick({R.id.mGeRen, R.id.mMDanWei, R.id.mMingXi, R.id.mBuKai})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.mGeRen:
                invoiceName="个人";
                if (mGeRen.isChecked()) {
                    mMDanWei.setChecked(false);
                    mInput.setVisibility(View.GONE);
                }
                break;
            case R.id.mMDanWei:
                invoiceName="单位";
                if (mMDanWei.isChecked()) {
                    mGeRen.setChecked(false);
                    mInput.setVisibility(View.VISIBLE);
                } else {
                    mGeRen.setChecked(true);
                    mInput.setVisibility(View.GONE);
                }
                break;
            case R.id.mMingXi:
                if (mMingXi.isChecked()) {
                    mBuKai.setChecked(false);
                    mFaPiaotaitou.setVisibility(View.VISIBLE);
                    flagmingxi = false;
                } else {
                    mBuKai.setChecked(true);
                    mInput.setVisibility(View.GONE);
                    mFaPiaotaitou.setVisibility(View.GONE);
                }
                break;
            case R.id.mBuKai:
                if (mBuKai.isChecked()) {
                    mMingXi.setChecked(false);
                    mInput.setVisibility(View.GONE);
                    mFaPiaotaitou.setVisibility(View.GONE);
                }
                break;
        }
    }
    //沉浸式状态栏
    public void immerSion() {
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
            window.setNavigationBarColor(Color.BLACK);
        }
    }
}
